package com.woniuxy.coder;

import java.io.StringReader;

import javax.json.Json;
import javax.websocket.DecodeException;
import javax.websocket.Decoder;

import javax.websocket.EndpointConfig;

import com.woniuxy.pojo.Order_dgy;

/*
 * 解码器
 */
public class OrderDecoder implements Decoder.Text<Order_dgy>{

	@Override
	public void destroy() {
		
	}

	@Override
	public void init(EndpointConfig arg0) {
		System.out.println("init---Decoder");
	}

	@Override
	public Order_dgy decode(String jsonMessage) throws DecodeException {
		return null;
		/*System.out.println("---------");
		JsonObject jsonObject = Json.createReader(new StringReader(jsonMessage)).readObject();
		Order_dgy order = new Order_dgy();
		order.setCheckIn(jsonObject.getString("checkIn"));
		order.setCheckOut(jsonObject.getString("checkOut"));
,		jsonObject.
		JsonArray jsonArray = jsonObject.getJsonArray("orderDetails");
		List<OrderDetail_dgy> detail_dgies = new ArrayList<OrderDetail_dgy>();
		OrderDetail_dgy orderDetail = new OrderDetail_dgy();
		Guest guest = new Guest();
		for(int i=0;i<jsonArray.size();i++){
			orderDetail.setRoomNumber(jsonArray.getJsonObject(i).getString("roomNumber"));
			guest.setGname(jsonArray.getJsonObject(i).getJsonObject("guest").getString("gname"));
			guest.setGidcard(jsonArray.getJsonObject(i).getJsonObject("guest").getString("gidcard"));
			orderDetail.setGuest(guest);
			detail_dgies.add(orderDetail);
		}
		order.setOrderDetails(detail_dgies);
		System.out.println("---"+detail_dgies);
		return order;*/
	}

	@Override
	public boolean willDecode(String jsonMessage) {
		try{
			Json.createReader(new StringReader(jsonMessage)).readObject();
			return true;
		}catch(Exception e){
			return false;
		}
	}

}